//
//  BusinessNetwork.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/9/2.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "BusinessNetwork.h"
#import "GFXNetworkHandle.h"
#import "GoodsTypeModel.h"
#import "HomeGoodsTypeModel.h"

NSString * const BusinessInfo = @"auth/get/shop/info";//商户信息
NSString * const SaleDetailList = @"auth/account/shop/user/sale/list";//销售明细
NSString * const ShopGoodsList = @"auth/product/normal/shop/list";//商户商品列表

NSString * const SellGoodsList = @"auth/order/buy/shop/list";//商户已售出

NSString * const GetShopGoodsDetail = @"auth/product/normal/editView";//获取商品信息
NSString * const ModifyGoodsDetail = @"auth/product/normal/edit";//修改商品信息
NSString * const AddGoods = @"auth/product/normal/add";//新增商品
NSString * const RemoveGoods = @"auth/product/normal/soldOut";//下架商品
NSString * const ShopGoodsType = @"productTypes/list/send";//首页商城商品分类
NSString * const AdderGoodsType = @"productTypes/list/send";//商家上传商品分类


@implementation BusinessNetwork

+ (void)getBusinessInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,SellerInfoModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:BusinessInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            SellerInfoModel *model = [SellerInfoModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getSaleDetailListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists,float sumAmount))response
{
    [[GFXNetworkHandle shareHandle]post:SaleDetailList params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *detailDict in json[@"result"][@"saleList"]) {
                SellerSaleDetailModel *model = [SellerSaleDetailModel objectWithDict:detailDict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists,[json[@"result"][@"sumAmount"] floatValue]);
        }else{
            response(NO,json[@"message"],nil,0);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil,0);
    }];
}

+ (void)getShopGoodsListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:ShopGoodsList params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                NormalShopGoodsModel *model = [NormalShopGoodsModel objectWithDict:dict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getShopGoodsDetailWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,AddGoodsModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:GetShopGoodsDetail params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            AddGoodsModel *model = [AddGoodsModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)modifyGoodsDetailWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:ModifyGoodsDetail params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}
+ (void)addGoodsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:AddGoods params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)removewGoodsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:RemoveGoods params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)getGoodsTypeWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *types))response
{
    [[GFXNetworkHandle shareHandle]post:ShopGoodsType params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *arr = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                HomeGoodsTypeModel *model = [HomeGoodsTypeModel objectWithDict:dict];
                [arr addObject:model];
            }
            response(YES,json[@"message"],arr);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getAdderGoodsTypeWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *types))response
{
    [[GFXNetworkHandle shareHandle]post:AdderGoodsType params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *arr = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                HomeGoodsTypeModel *model = [HomeGoodsTypeModel objectWithDict:dict];
                [arr addObject:model];
            }
            response(YES,json[@"message"],arr);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getSellGoodsListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:SellGoodsList params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *arr = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                SingleListModel *model = [SingleListModel objectWithDict:dict];
                [arr addObject:model];
            }
            response(YES,json[@"message"],arr);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}


@end
